package com.hr.demo.controller;

import com.hr.demo.annotation.Token;
import com.hr.demo.config.State;
import com.hr.demo.entity.File;
import com.hr.demo.entity.ResponseJson;
import com.hr.demo.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/auth/file")
public class FileController {
    @Autowired
    private FileService fileService;

    @Token
    @PostMapping("/getmyfile")
    public ResponseJson getMyFile(){
        return fileService.getMyFile();
    }

    @Token
    @PostMapping("/setmyfile")
    public ResponseJson setMyFile(@RequestParam("file")MultipartFile file)throws Exception{
       if (file.isEmpty()){
           return new ResponseJson(State.FAIL,"请上传正确的文件");
       }
        return fileService.seyMyFile(file);
    }
}
